package d.max.rwp.ui.component;

import android.content.Context;
import android.util.AttributeSet;
import android.widget.ImageView;

/**
 * author: Maxim Dybarskiy
 * date:   Aug 28, 2011
 * time:   2:17:32 PM
 */
public class ImageViewCheckable extends ImageView {
    
    private boolean checked;
    private int iconCheckedId;
    private int iconUncheckedId;

    public ImageViewCheckable(Context context) {
        super(context);
    }

    public ImageViewCheckable(Context context, AttributeSet attrs, int defStyle) {
        super(context, attrs, defStyle);
    }

    public ImageViewCheckable(Context context, AttributeSet attrs) {
        super(context, attrs);
    }
    
    public boolean isChecked() {
        return checked;
    }

    public void setChecked(boolean checked) {
        this.checked = checked;
        updateIcon();
    }

    public int getIconCheckedId() {
        return iconCheckedId;
    }

    public void setIconCheckedId(int iconCheckedId) {
        this.iconCheckedId = iconCheckedId;
    }

    public int getIconUncheckedId() {
        return iconUncheckedId;
    }

    public void setIconUncheckedId(int iconUncheckedId) {
        this.iconUncheckedId = iconUncheckedId;
    }

    private void updateIcon() {
        this.setBackgroundResource(checked ? iconCheckedId : iconUncheckedId);
    }
}
